package org.gvp.manager.repository.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.gvp.manager.mapper.GatewayRouteFactoryMapper;
import org.gvp.manager.mapper.GatewayRouteMapper;
import org.gvp.manager.pojo.GatewayRoute;
import org.gvp.manager.pojo.GatewayRouteFactory;
import org.gvp.manager.repository.GatewayRouteFactoryRepository;
import org.gvp.manager.repository.GatewayRouteRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class GatewayRouteFactoryRepositoryImpl implements GatewayRouteFactoryRepository {
    private final GatewayRouteFactoryMapper routeFactoryMapper;

    @Override
    public List<GatewayRouteFactory> searchByRouterId(Integer routeId) {
        return this.routeFactoryMapper.selectList(Wrappers.<GatewayRouteFactory>lambdaQuery()
                .select(
                        GatewayRouteFactory::getId,
                        GatewayRouteFactory::getKey,
                        GatewayRouteFactory::getName,
                        GatewayRouteFactory::getArgs,
                        GatewayRouteFactory::getRouteId,
                        GatewayRouteFactory::getMetadata,
                        GatewayRouteFactory::getType,
                        GatewayRouteFactory::getRemark
                )
                .eq(GatewayRouteFactory::getRouteId, routeId)
        );
    }

    @Override
    public int modify(GatewayRouteFactory pojo) {
        return this.routeFactoryMapper.updateById(pojo);
    }

    @Override
    public int append(GatewayRouteFactory pojo) {
        return this.routeFactoryMapper.insert(pojo);
    }
}
